//index.js
//获取应用实例
var app = getApp()
Page({
    data: {
        loadingHidden:false,
        loadmoreHidden:false,
        list: [],
        cet4:[],
        cet6:[],
        swiper: {
            indicatorDots: true,
            autoplay: true,
            interval: 2000,
            duration: 300
        }
    },
    onLoad: function() {
        var that = this;
        wx.request({
            url: "http://localhost/mock/videos",
            method: "GET",
            success: function(res) {
                console.log('on load ==>',res);
                setTimeout(function() {
                    that.setData({
                        list: res.data,
                        loadingHidden: true
                    });
                }, 600);
            }
        });

        this.getEnglishWord('四级');
        this.getEnglishWord('六级');
    },
    actionTolower: function() {
        var that = this;
        this.setData({
          loadmoreHidden: false
        });
        wx.request({
            url: "http://localhost/mock/videos",
            success: function(res) {
                console.log("视频列表",res);
                that.data.loadingHidden=false;
                setTimeout(function() {
                    that.setData({
                        list: that.data.list.concat(res.data),
                        loadingHidden: true,
                        loadmoreHidden:true
                    })
                }, 1000);
            }
        })
    },
    levideo:function (obj) {
        var objInfo = obj.currentTarget.dataset.obj;
        wx.navigateTo({
            url: "../levideo/levideo",
            success: function(res) {
                console.log('传递视频信息');
                res.eventChannel.emit('videoInfo',objInfo);
            }
        })
    },
    gotoStudy: function(e) {
        console.log('cet4',this.data.cet4);
        console.log('goto study',e);
        let course_num = e.currentTarget.dataset.course_num;
        let class_id = e.currentTarget.dataset.class_id;
        wx.navigateTo({
          url: '../english_word/english_word?course_num='+course_num + '&class_id=' + class_id
        })
    },
    getEnglishWord: function(value) { 
        var that = this;
        console.log('get english word ', value);
        var url = 'http://rw.ylapi.cn/reciteword/list.u';
        var uid = '11422';
        var appKey = '055aa48e889bca3fe7f6a27702af80d8';
        var result = null;
        wx.request({
          url: url + '?name=' + new String(value) + '&uid=' + new String(uid) + '&appkey=' + new String(appKey),
          method: 'POST',
          header: {'Content-Type': 'application/json;charset=utf-8'},
          data:{params:{name: new String(value), uid: uid, appkey: appKey}},
          success: function(res) {
            if(res.data.code == 1000) {
                if(new String(value).indexOf('四级') !== -1) {
                    that.setData({cet4: res.data.datas});
                }
                if(new String(value).indexOf('六级') !== -1) {
                    that.setData({cet6: res.data.datas});
                }
                console.log(res.data.datas);
            } else {
                result =  [];
            }
          },
          fail: function(res) {
              result =  [];
          }
        });
    }







})
